Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] give data plugin control of filter extraction, injection, and migrations #120305

Conversation

drewdaemon
Copy link
Contributor

@drewdaemon drewdaemon commented Dec 2, 2021

Summary

Resolves #114482

  • use data plugin's extract/inject functions instead of our own local stuff
  • apply filter migrations to filters within Lens visualizations (both standalone and embedded)
  • introduces a custom definition of lens equality

Question for core team: I duplicated the mergeMigrationFunctionMaps function to make it work for a similar type SavedObjectMigrationMap which passes an addition context argument. See the duplicate function here. Any thoughts on how/if to unify these?

How to Test

Saved Object Migrations

  • Add the following dummy filter migration here
export const getAllMigrations = (): MigrateFunctionsObject => {
  return {
    '8.1.0': (filters: Filter[]) => filters.map((filter) => ({ ...filter, migrated: true })),
  };
};
  • Start and open Kibana
  • Visit "Stack Management" -> "Saved objects"
  • Import these saved objects
  • this will add three objects to verify (plus the index pattern)
    • Dashboard with Embedded Lens Visualizations with Filters
    • standalone table with filters
    • standalone bar chart with filter
  • Verify that each filter in the visualization states
    1. Has no indexRefName property. Instead, it should have an index property.
    2. Has a migrated: true property.

"Unsaved changes" Modal

Setup

  • create new lens visualization
  • save outside of a dashboard
  • refresh the page. You should still be on the Lens editor.

Does NOT prompt if nothing has changed

  • Click "Visualize Library" in the breadcrumbs
    Expected No "Unsaved changes" warning is shown

DOES prompt if something has changed

  • Go back to your visualization
  • Drag a new field to your workspace.
  • Click "Visualize Library" in the breadcrumbs
    Expected: You should see "Unsaved changes" warning

Special case: datasource change

  • Refresh the page
  • Set the visualization type to "Metric" on "Record Count" (this setup is necessary to test the datasource equality check in isolation. Using a "Metric" visualization ensures that nothing in the visualization state will change when we change the datasource's data view).
  • Save visualization
  • Change the data view used by the datasource

Screen Shot 2021-12-17 at 11 18 47 AM

  • Click "Visualize Library" in the breadcrumbs
    Expected: You should see "Unsaved changes" warning

Checklist

Risk Matrix

Risk Probability Severity Mitigation/Notes
There are currently no filter migrations defined, so we are building for a future scenario. Medium Medium Unit tests cover applying filter migrations within a Lens visualization. In addition, we will manually test by adding a dummy filter migration and ensuring it is applied.
Difference between Lens extractFilterReferences and Data plugin's extract. Lens removes filter.meta.value since it wasn't persistable at some point. Low Medium A manual test of saving a Lens visualization with filters should alert us to any issues here. In addition, data plugin owners may be able to confirm that value is no longer non-persistable.

@drewdaemon drewdaemon force-pushed the 114482/correctly-apply-filter-migrations-in-saved-objects branch from da9dc2a to 7218e4f Compare December 3, 2021 16:21
@drewdaemon drewdaemon changed the title 114482/correctly apply filter migrations in saved objects [Lens] correctly apply filter migrations in saved objects Dec 3, 2021
@drewdaemon drewdaemon added release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. release_note:skip Skip the PR/issue when compiling release notes v8.1.0 Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure and removed release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. labels Dec 3, 2021
@drewdaemon drewdaemon changed the title [Lens] correctly apply filter migrations in saved objects [Lens] give data plugin control of filter extraction, injection, and migrations Dec 3, 2021
@drewdaemon
Copy link
Contributor Author

drewdaemon commented Dec 3, 2021

@flash1293 I am currently injecting the inject/extract functions from the data plugin's FilterManager class during the setup cycle. It occurs to me that publicly exporting these functions instead would enable us to import them statically. It's a simpler solution. Here is an illustration of what I mean.

What do you think about those options?

@flash1293
Copy link
Contributor

@andrewctate Agree, statically exporting these helpers seems like the easiest approach. Similar to how the search namespace is exported here maybe:

@ppisljar @Dosant do you have any guidance here how it should work?

@drewdaemon drewdaemon force-pushed the 114482/correctly-apply-filter-migrations-in-saved-objects branch from 172956b to 9ff5fa9 Compare December 6, 2021 17:52
@drewdaemon drewdaemon force-pushed the 114482/correctly-apply-filter-migrations-in-saved-objects branch from e9adaed to 6ce57e3 Compare December 6, 2021 18:37
…ts' of github.com:andrewctate/kibana into 114482/correctly-apply-filter-migrations-in-saved-objects
@drewdaemon drewdaemon requested a review from flash1293 January 5, 2022 14:43
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again and works fine, thanks! I would appreciate another look just to make sure - as discussed these changes are really important to get right

@drewdaemon
Copy link
Contributor Author

@elasticmachine merge upstream

@drewdaemon
Copy link
Contributor Author

@alexwizp @stratoula Tim suggested one of you to take a look at the migrations in this PR. Would one of you be available to give it a review?

@stratoula
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested various Lens charts with filter combinations created in v8 and migrated to v8.1. They seem to work fine.

I just have a question for the "Unsaved changes modal"

Let's say that I have an embedded lens chart. I dont change anything, I just select a different dataview from the left panel
For example here
image

I changed the index pattern dropdown from flights to ecommerce but I didn't make any change to the chart. Why do I see the modal?

I tested it in v8 and the modal doesn't appear (which makes more sense to me)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2747 2748 +1
lens 246 248 +2
total +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1023.3KB 1023.9KB +599.0B
osquery 939.3KB 939.2KB -14.0B
total +585.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 41.0KB 41.1KB +101.0B
Unknown metric groups

API count

id before after diff
data 3341 3342 +1
lens 263 265 +2
total +3

References to deprecated APIs

id before after diff
lens 269 278 +9

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@drewdaemon
Copy link
Contributor Author

@mbondyra good find. I will look into how difficult it would be to exclude that particular setting from the state comparison.

On the other hand, the selected data view is persisted in the saved object according to @flash1293 , so there's may also be argument for warning the user if they navigate away without saving. I'm not sure on what the user would expect.

@stratoula
Copy link
Contributor

stratoula commented Jan 13, 2022

Do we? Even if it is not used at all? In my example above I just changed index pattern from the dropdown, the field list is updated but I haven't used any of them in my viz. I cant replicate it tbh. I checked the SO and there is no reference of the unused dataview. 🤔

@flash1293
Copy link
Contributor

@stratoula It's not used on the dashboard, but it's used in the editor to re-open the data view in the data panel the user had opened the last time. It's stored in the references as "current index pattern":
Screenshot 2022-01-13 at 11 26 44

I don't feel strongly about changing that and just not saving this piece of the state (it doesn't seem super relevant in the first place), but I would like to move it out of this PR if possible.

@stratoula
Copy link
Contributor

Yes you are right Joe. It is saved on the SO but it doesn't seem to be used anywhere. If I save a lens chart like that
image (13)

and then re-open it, the dataview in the dropdown is the one used on the chart and not the one I selected on the dropdown.
I will create an issue for that, it doesn't seem necessary to keep this in the SO if it is not used anywhere.

@andrewctate no need to block this PR for this. I think it works fine 👍

@drewdaemon
Copy link
Contributor Author

@tomsonpl thanks for the review!

@stratoula okay, I will merge as-is. Feel free to assign that issue to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Correctly handle references and migrations for filters in saved objects
10 participants